package com.eeda123.jfinal.route;

import com.jfinal.core.Controller;
import com.jfinal.kit.PropKit;

import java.io.File;
import java.io.FileNotFoundException;

public class DynamicRouteBaseController extends Controller {
    public static String DEFAULT_ROUTE = "/dynamic_route";

    public static String engineName = "";

    //如需要render外部目录, 则设置一下这个目录变量
    public static String webRoot = "";

    public void render(String view) {
        String viewPath = "";
        if(!view.startsWith(File.separator)) {
            viewPath = webRoot + File.separator + view;
        }else{
            viewPath = webRoot + view;
        }
        try {//优先读取外部目录
        	File file = new File(viewPath);
        	if(file.exists()){
        		super.render(new ExtRender(viewPath));
        	} else {
        		throw new FileNotFoundException(); 
        	}
        }catch (Exception ex){
            //如果找到不到文件报错, 再读取项目运行目录webRoot下的文件
            super.render(view);
        }
    }

}
